﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <assert.h>
#include <vector>
#include <string>
using namespace std;
#include "mymap.h"
#include "myset.h"
void Print(const Aurora::set<int>& s)
{
    Aurora::set<int>::const_iterator it = s.end();
    while (it != s.begin())
    {
        --it;
        // 不支持修改
        //*it += 2;
        cout << *it << " ";
    }
    cout << endl;
}
void set_test()
{
    Aurora::set<int> s;
    /*s.insert(8);
    s.insert(1);
    s.insert(4);
    s.insert(2);*/
    //int a[] = { 16, 3, 7, 11, 9, 26, 18, 14, 15 };
    //特殊带有双旋场景测试用例
    int a[] = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14 };
    for (const auto& e : a)
    {
        s.insert(e);
    }
    
    Aurora::set<int>::iterator it = s.begin();
    //*it += 10;
    while (it != s.end())
    {
        cout << *it << " ";
        ++it;
    }
    cout << endl;
    Print(s);
}
void Print(const Aurora::map<int,int>& m)
{
    Aurora::map<int,int>::const_iterator it = m.end();
    //it->first += 10;
    //it->second += 10;
    while (it != m.begin())
    {
        --it;
        cout << it->first << "->" << it->second << " ";
    }
    cout << endl;
}
void map_test()
{
    Aurora::map<int, int> m;
    /*m.insert({ 4,4 });
    m.insert({ 1,1 });
    m.insert({ 7,7 });
    m.insert({ 2,2 });*/
    //int a[] = { 16, 3, 7, 11, 9, 26, 18, 14, 15 };
    //特殊带有双旋场景测试用例
    int a[] = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14 };
    for (const auto& e : a)
    {
        m.insert({e,e});
    }
    Aurora::map<int, int>::iterator it = m.begin();
    while (it != m.end())
    {  
        cout << it->first << ":" << it->second << endl;
        ++it;
    }
    cout << endl;
    it = m.end();
    while (it != m.begin())
    {
        --it;
        cout << it->first << ":" << it->second << endl;
    }
    cout << endl;
    Print(m);
    Aurora::map<string, string> dict;
    dict.insert({ "sort","排序" });
    dict.insert({ "left","左边" });
    dict.insert({ "right","右边" });
    dict["left"] = "左边,剩余";//以前存在,那就是修改
    dict["insert"] = "插入";//插入+修改
    dict["string"];//只插入
    for (const auto& kv : dict)
    {
        cout << kv.first << ":" << kv.second << endl;
    }
    cout << endl;
    //统计水果次数
    Aurora::map<string, int> count;
    string str[] = { "香蕉","西瓜","香蕉","苹果","西瓜","香蕉","香蕉","苹果","西瓜" };
    for (const auto& e : str)
    {
        count[e]++;
    }
    for (const auto& kv : count)
    {
        cout << kv.first << ":" << kv.second << endl;
    }
    cout << endl;
}
int main()
{
    set_test();
    map_test();
    return 0;
}

